<template>
  <span>获取验证码({{ time }}s)</span>
</template>

<script>
export default {
  name: "CountDone",
  data() {
    return {
      time: 5,
    };
  },
  props: {
    flag: Boolean,
  },
  watch: {
    flag: {
      handler() {
        let timer = setInterval(() => {
          this.time--;
          if (this.time == 0) {
            this.$emit("getFlag", false);
            clearInterval(timer);
          }
        }, 1000);
      },
      immediate: true,
    },
  },
};
</script>

<style lang="scss" scoped></style>
